package com.darren.center.design.patterns.config;

import com.darren.center.design.patterns.command.BaseActionMapper;
import com.darren.center.design.patterns.command.Dispatcher;
import com.darren.center.design.patterns.command.DispatcherHandlerChain;
import com.darren.center.design.patterns.command.Handler;
import com.darren.center.design.patterns.handler.AuthHandler;
import com.darren.center.design.patterns.handler.InterfaceControlHandler;
import com.darren.center.design.patterns.handler.VerifyHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * <h3>design-patterns</h3>
 * <p></p>
 *
 * @author : Darren
 * @date : 2021年06月14日 20:31:53
 **/
@Component
public class BeanConfig {

    @Autowired
    private AuthHandler authHandler;
    @Autowired
    private InterfaceControlHandler interfaceControlHandler;
    @Autowired
    private VerifyHandler verifyHandler;

    @Bean(name = "open-action-ActionMapper")
    public BaseActionMapper getBaseActionMapper(){
        return new BaseActionMapper();
    }

    @Bean(name = "open-action-Dispatcher")
    public Dispatcher getDispatcher(){
        return new Dispatcher();
    }

    @Bean(name = "open-action-DispatcherHandlerChain")
    public DispatcherHandlerChain getDispatcherHandlerChain(){
        DispatcherHandlerChain dispatcherHandlerChain = new DispatcherHandlerChain();
        List<Handler> handlers = new ArrayList<>(3);
        handlers.add(authHandler);
        handlers.add(interfaceControlHandler);
        handlers.add(verifyHandler);
        dispatcherHandlerChain.setHandlers(handlers);
        return dispatcherHandlerChain;
    }

}

